﻿CREATE PROCEDURE [dbo].[KP_DangKyKDTraHoSo]
	@Stt_Rec nvarchar(12),		
	--@Ma_Tt int,
	@User0 nvarchar(23),
	@Client0 nvarchar(47)	
AS
BEGIN
	Declare @Ma_Tt_Ht int,@Ghi_Chu_Ht nvarchar(512)
	Select @Ma_Tt_Ht=Ma_Tt,@Ghi_Chu_Ht=Ghi_Chu from tblDangKyKD where Stt_Rec=@Stt_Rec
		--AND Ma_Tt=@Ma_Tt
	if @Ma_Tt_Ht is not null
	begin
		Insert Into [tblNhatKyHs]([Stt_Rec],[Ma_Tt_Cu],[Ma_Tt],[Ghi_Chu],[User0],[Date0],[Client0])
		VALUES(@Stt_Rec,@Ma_Tt_Ht,@Ma_Tt_Ht,@Ghi_Chu_Ht,@User0,getdate(),@Client0);
		
		Insert Into [tblNhatKyHs]([Stt_Rec],[Ma_Tt_Cu],[Ma_Tt],[Ghi_Chu],[User0],[Date0],[Client0])
		VALUES(@Stt_Rec,@Ma_Tt_Ht,@Ma_Tt_Ht,N'Cán bộ 1 cửa trả hồ sơ',@User0,getdate(),@Client0);
		
		Update tblDangKyKD set Da_Tra=1,Ghi_Chu=N'Đã trả hồ sơ' Where Stt_Rec=@Stt_Rec
		--AND Ma_Tt=@Ma_Tt
		RETURN 0;
	end
	ELSE
		RETURN -1;
END	
